package com.mfh.auto.create.mvvm.autocreatemvvm.file.v1

import com.intellij.psi.PsiDirectory
import com.mfh.auto.create.mvvm.autocreatemvvm.Config
import com.mfh.auto.create.mvvm.autocreatemvvm.camelCaseToUnderscore
import com.mfh.auto.create.mvvm.autocreatemvvm.file.BaseFileModel
import com.mfh.auto.create.mvvm.autocreatemvvm.utils.CreateFileUtils

object DialogFileModel : BaseFileModel() {

    override fun buildFileName() = "${Config.name}DialogModel.kt"

    override fun buildContentString(directory: PsiDirectory): String {
        val name = Config.name
        val bindingName = "Dialog${name}Binding"
        val projectPackage = getProjectPackage(directory)
        return buildString {
            appendLine("package ${CreateFileUtils.getPackageByDirectory(directory)}")
            appendLine()
            appendLine("import android.content.Context")
            appendLine("import ${Config.libPackageName}.base.BaseDialogModel")
            if (projectPackage.isNotEmpty()) {
                appendLine("import ${projectPackage}.R")
                appendLine("import ${projectPackage}.databinding.$bindingName")
            }
            appendLine()
            appendLine("/**")
            appendLine(" * @desc: ${Config.desc}")
            appendLine(" */")
            appendLine("class ${name}DialogModel : BaseDialogModel<${bindingName}>() {")
            appendLine()
            appendLine("    override fun layoutId() = R.layout.dialog_${name.camelCaseToUnderscore()}")
            appendLine()
            appendLine("    override fun onDialogCreated(context: Context) {")
            appendLine("        binding.model = this")
            appendLine("    }")
            appendLine()
            appendLine("}")
        }
    }
}